package com.yb0os1.mapper;

import com.yb0os1.dto.OrderConditionSearchDTO;
import com.yb0os1.entity.Orders;
import com.yb0os1.entity.TurnoverStatistics;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderMapper {

    void insert(Orders orders);
    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from orders where user_id=#{userId} and id =#{id}")
    Orders getById(Long userId, Long id);


    List<Orders> list(OrderConditionSearchDTO orderConditionSearchDTO);

    @Select("select count(*) from orders where status = #{pendingPayment}")
    Integer statistics(Integer pendingPayment);

    @Select("select id from orders where number=#{orderNumber}")
    Integer getIdByOrderNumber(String orderNumber);



    List<TurnoverStatistics> getTurnoverStatistics(LocalDate begin, LocalDate end);

    @Select("select count(*) totalUserNumber from user where date(create_time) <= #{begin}")
    Integer getTotalNumber(LocalDate begin);

    Integer getOrdersStatistics(LocalDate time, Integer status,boolean isEqual);

    @Select("select sum(orders.amount) from orders where status = 5 and date(order_time)=#{today}")
    BigDecimal getTotalAmount(LocalDate today);

    @Select("select sum(amount) from orders where date(order_time) between #{begin} and #{end}")
    BigDecimal getTurnover(LocalDate begin, LocalDate end);


    Integer getOrders(LocalDate begin, LocalDate end, Integer status);
}
